package com.thingsgrid.firmware.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mongodb.client.result.UpdateResult;
import com.thingsgrid.firmware.service.IFirmwareService;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@AllArgsConstructor
@RequestMapping("/firmware")
public class FirmwareController {
	private IFirmwareService service;
	private MongoTemplate template;

	//获取当前状态下的设备
	@PostMapping("/getDevicelist")
	public R<List> getDevicelist(Page page, @RequestParam("methodid") String methodid, @RequestParam("stats") Integer stats) {
		List<Map> device = service.getDevicelist(page, methodid, stats);
		return R.data(device);
	}
	//显示固件升级主页面
	@PostMapping("/getfirmware")
	public R<Map> getFirmware(Page page, String product_type, String firmware_name, String product_name) {
		Map map = service.getFirmware(page, product_type, firmware_name, product_name);
		return R.data(map);
	}

	//删除应用升级记录
	@PostMapping("/deleteRecord")
	public R deleteRecord(String methedId) {
		UpdateResult mode = service.deleteRecord(methedId);
		if (mode.getMatchedCount() > 0){
			return R.status(true);
		}

		return R.status(false);

	}

}
